<?php
namespace app\common\model;

use think\model\concern\SoftDelete;

class SystemAdmin extends Base
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';

    /**
     * 启用||禁用
     */
    public static function setStatus($id){
        $info = self::getFind(['id' => $id]);

        if($info['status'] == 0){
            $status       = 1;
            $back['flag'] = 1;
            $back['msg']  = '启用成功';
        }else{
            $status       = 0;
            $back['flag'] = 0;
            $back['msg']  = '禁用成功';
        }

        $data = [
            'id'      => $id,
            'status'  => $status,
        ];
        
        self::update($data);
        return $back;
    }

    public function getRoleAttr($val)
    {
        if($val == 0){
            return '超级管理员';
        }

        return SystemRole::getVal(['id' => $val], 'name');
    }

    public function getLastTimeAttr($val)
    {
        if($val == 0){
            return '-';
        }

        return date('Y-m-d H:i:s', $val);
    }
}